package com.onepiece.shipelves.common.exception;

import com.onepiece.shipelves.common.enums.BaseExceptionEnum;

import java.util.Objects;

/**
 * @author ting
 * @version v1.0
 * @ClassName: SystemException
 * @date 2019-04-26
 */
public class SystemException extends RuntimeException {

    protected String code;

    protected String message;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public SystemException() {
        super();
    }

    public SystemException(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public SystemException(BaseExceptionEnum baseExceptionEnum) {
        this.code = baseExceptionEnum.getExceptionCode();
        this.message = baseExceptionEnum.getExceptionMessage();
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        SystemException that = (SystemException) o;
        return code.equals(that.code) &&
                message.equals(that.message);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, message);
    }
}
